package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单控制层
 *
 * @author wkh
 * @date 2024/6/19 9:31
 */
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "订单管理接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 订单统计
     */
    @GetMapping("/statistics")
    @ApiOperation("订单统计")
    public Result<OrderStatisticsVO> countOrderStatus() {
        log.info("订单统计");
        OrderStatisticsVO orderStatisticsVO = orderService.countOrderStatus();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 条件搜索订单
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("条件搜索订单")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("条件搜索订单");
        PageResult pr = orderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(pr);
    }

    /**
     * 查询订单详情
     */
    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public Result<OrderVO> getOrderDetails(@PathVariable Long id) {
        log.info("查询订单详情");
        OrderVO orderVO = orderService.getOrderDetailsByOrderId(id);
        return Result.success(orderVO);
    }

    /**
     * 取消订单
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        log.info("取消订单");
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 完成订单
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("订单完成")
    public Result complete(@PathVariable Long id) {
        log.info("订单完成");
        orderService.complete(id);
        return Result.success();
    }

    /**
     * 订单拒绝
     */
    @PutMapping("/rejection")
    @ApiOperation("订单拒绝")
    public Result reject(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        log.info("订单拒绝");
        orderService.reject(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 订单确认
     */
    @PutMapping("/confirm")
    @ApiOperation("订单确认")
    public Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {
        log.info("订单确认");
        orderService.confirm(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 订单配送
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("订单配送")
    public Result delivery(@PathVariable Long id) {
        log.info("订单配送");
        orderService.delivery(id);
        return Result.success();
    }
}
